public class MyBlockingQueue {
    private String[] data = null;
    private int head = 0;
    private int tail = 0;
    private int size = 0;

    public MyBlockingQueue(int capacity) {
        data = new String[capacity];
    }

    public void put(String str) throws InterruptedException {
        synchronized (this) {
            if (size == data.length) {
                this.wait();
            }
            data[tail] = str;
            tail++;
            size++;
            if (tail == data.length) {
                tail = 0;
            }
            this.notify();
        }
    }

    public String task() throws InterruptedException {
        String tmp = "";
        synchronized (this) {
            if (size == 0) {
                this.wait();
            }
            tmp = data[head];
            head++;
            size--;
            if(head == data.length){
                head = 0;
            }
            this.notify();
        }
        return tmp;
    }
}

